package com.dsteiner.xelavos.client.controller;

import com.dsteiner.xelavos.client.domain.User;

public interface IHistoryToken <T> {
	final String SELECTED_TAB = "sb";
	final String OBJECT_ID = "oid";
	final String SHOW_MESSAGE_BOX = "smb";
	
	String getName();
	String getValueAsString();
	void parse(String token);
	IHistoryToken<T> setValue(T value);
	T getValue();
	
	IHistoryToken<Integer> HT_SELECTED_TAB = new IHistoryToken<Integer>(){
		private Integer tabId;
		public String getName() {
			return SELECTED_TAB;
		}
		public String getValueAsString() {
			return tabId.toString();
		}
		public IHistoryToken<Integer> setValue(Integer value) {
			this.tabId = value;
			return this;
		}
		public void parse(String token) {
			this.tabId = new Integer(token);
		}
		public Integer getValue() {
			return tabId;
		}
	};
	
	IHistoryToken<String> HT_OBJECT_ID = new IHistoryToken<String>(){
		private String objectId;
		public String getName() {
			return OBJECT_ID;
		}
		public String getValueAsString() {
			return objectId;
		}
		public IHistoryToken<String> setValue(String value) {
			this.objectId = value;
			return this;
		}
		public void parse(String token) {
			this.objectId = token;
		}
		public String getValue() {
			return objectId;
		}
	};
	
	IHistoryToken<User> HT_SHOW_MESSAGE_BOX = new IHistoryToken<User>(){
		private User user;
		public String getName() {
			return SHOW_MESSAGE_BOX;
		}
		public String getValueAsString() {
			return user.getId()+";"+user.getFirstName();
		}
		public IHistoryToken<User> setValue(User user) {
			this.user = user;
			return this;
		}
		public void parse(String token) {
			String[] split = token.split(";");
			user = new User();
			user.setId(split[0]);
			user.setFirstName(split[1]);
		}
		public User getValue() {
			return user;
		}
	};
}
